package com.analyzer.tcp;

import java.lang.reflect.Method;

import hprose.server.HproseTcpServer;

import org.apache.log4j.Logger;

/** @author wyy 
 * @version 1.0 
 * 2015-11-17 上午09:49:43
 */

public class AnalyzerServer {
	
	private static Logger logger=Logger.getLogger(AnalyzerServer.class);

	public void start(final String className,final int port){
		new Thread(new Runnable() {
			public void run() {
				try {
					HproseTcpServer server= new HproseTcpServer("tcp://0.0.0.0:"+port);	
					
					Class<? extends Object> cla=Class.forName(className).newInstance().getClass();
					
					Method[] methods=cla.getDeclaredMethods();
					for (Method method : methods) {
						System.out.println(method.getName());
						server.add(method.getName(),cla);
					}
					System.out.println("server start at port "+port);
					server.setEnabledThreadPool(true);
					server.start();
					logger.error("server start at port "+port);
					System.in.read();
					server.stop();
					logger.error("server stop");
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}).start();
	}
}

